<template>
    <div>
        <el-table
            ref="customerTable"
            :data="tableData"
            stripe
            v-loading="loading"
            border
            style="width: 100%"
            @selection-change="getSelectVal"
        >
            <!-- @selection-change="handleSelectionChange" -->
            <el-table-column type="selection" width="55" align="center">
            </el-table-column>
            <el-table-column
                type="index"
                label="序号"
                width="55"
                align="center"
            />
            <el-table-column
                prop="materialCode"
                label="物料编码"
            ></el-table-column>
            <el-table-column
                prop="materialName"
                label="物料名称"
            ></el-table-column>
            <el-table-column prop="kingDocCode" label="单据编码">
            </el-table-column>
            <el-table-column prop="customerName" label="客户"></el-table-column>
            <el-table-column prop="number" label="销售数量"></el-table-column>
            <el-table-column prop="saleCode" label="销售编码"></el-table-column>
            <el-table-column
                prop="deliveryDate"
                label="交货日期"
            ></el-table-column>
        </el-table>
        <el-pagination
            class="pagination"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
        >
        </el-pagination>
        <div>
            <el-button size="small" type="primary" @click="submit"
                >确定</el-button
            >
            <el-button
                size="small"
                type="primary"
                @click="$emit('update:visible', false)"
                >取消</el-button
            >
        </div>
    </div>
</template>

<script>
import { getSaleList } from "@/api/system/sale";
export default {
    data() {
        return {
            tableData: [],
            page: 1, //当前页
            limit: 10, //每页条数
            total: 0,
            rowList: [],
            loading: false,
        };
    },
    methods: {
        //分页器size
        handleSizeChange(val) {
            this.limit = val;
            this.getDataList();
        },
        //分页器当前页
        handleCurrentChange(val) {
            this.page = val;
            this.getDataList();
        },
        getSelectVal(val) {
            this.rowList = val;
        },
        submit() {
            if (this.rowList.length) {
                this.$emit("update:visible", false);
                this.$emit("getSelectVal", this.rowList);
            } else {
                this.$message.warning("请至少选择一项");
            }
        },
        getDataList() {
            this.loading = true;
            getSaleList({
                page: this.page,
                limit: this.limit,
            }).then((res) => {
                this.tableData = res.data.records;
                this.loading = false;
            });
        },
    },
    mounted() {
        this.getDataList();
    },
};
</script>

<style></style>
